{% extends "home/common.html" %}
{% block content %}
	<!-- //网站头部 -->
	<div id="mr-mainbody" class="container mr-mainbody">
		<div class="row">
			<!-- 页面主体内容 -->
			<div id="mr-content"
				class="mr-content col-xs-12 col-sm-12 col-md-9 col-md-push-3">
				<div id="mrshop" class="mrshop common-home">
					<div class="container_oc">
						<div class="row">
							<div id="content_oc" class="col-sm-12 view-product">
								<!-- 根据商品ID获取并显示商品信息 -->

								<!-- 显示商品详细信息 -->
								<div class="row">
									<div class="col-xs-12 col-md-4 col-sm-4">
										<ul class="thumbnails" style="list-style: none">
											<li><a class="thumbnail" href="#">
                                                <img src="{{url_for('static',filename='images/goods/'+goods.picture)}}"></a>
                                            </li>
										</ul>
									</div>
									<div class="col-xs-12 col-md-8 col-sm-8">
										<div style="margin-left: 30px; margin-top: 20px">
											<h1 class="product-title">{{goods.name}}</h1>
											<ul class="list-unstyled price"><li><h2>{{goods.current_price}}元</h2></li></ul>
											<ul class="list-unstyled price"><li>原价: {{goods.original_price}}元</li></ul>
											<div class="rating"><p>商城sdsd活动：全场满21199包邮</p></div>
											<div id="product"><hr>
												<div class="form-group">
													<label class="control-label" for="shuliang"> 数量 </label>
													<input type="number" name="quantity" value="1" size="2"
														id="shuliang" class="form-control"> 
                                                    <label class="control-label" for="shuliang"> 还有库存{{goods.stock}}件</label>
                                                    <br>
													<div class="btn-group">
                                                        {% if goods.stock > 0 %}
                                                        <button type="button" onclick="addCart_detail()" class="btn btn-primary btn-primary">
                                                            <i class="fa fa-shopping-cart"></i> 添加到购物车
                                                        </button>
                                                        <button type="button" id="button-wishlist" data-toggle="tooltip" class="btn"
                                                         title="收藏" data-original-title="收藏"> <i class="fa fa-heart"></i></button>
                                                        {% else %}
                                                        <button type="button" class="btn btn-primary btn-primary" disabled>
                                                            <i class="fa fa-shopping-cart"></i> 库存不足，无法添加
                                                        </button>
                                                        <button type="button" id="button-wishlist" data-toggle="tooltip" class="btn"
                                                         title="收藏" data-original-title="收藏"> <i class="fa fa-heart"></i></button>
                                                        {% endif %}



														<!-- <button type="button" onclick="addCart_detail()" class="btn btn-primary btn-primary">
															<i class="fa fa-shopping-cart"></i> 添加到购物车</button>
														<button type="button" id="button-wishlist" data-toggle="tooltip" class="btn"
														 title="收藏" data-original-title="收藏"> <i class="fa fa-heart"></i></button> -->
													</div>
												</div>
											</div>
										</div>
									</div>
									<div class="col-sm-12 description_oc clearfix">
										<ul class="nav nav-tabs htabs">
											<li class="active" style="width: 150px"><a href="#tab-description" data-toggle="tab"
												aria-expanded="true">商品描述</a></li>
										</ul>
										<div class="tab-content" style="border: 1px solid #eee; overflow: hidden;">
											<div class="tab-pane active" id="tab-description">
                                                {{goods.introduction}}
                                            </div>
										</div>
									</div>
								</div>
								<!-- 显示相关商品 -->
                                <div class="mr-module related-products">
                                    <h3 class="module-title ">相关商品</h3>
                                    <!-- 显示底部相关商品 -->
                                    <div class="row">
                                    {% for item in similar_goods%}
                                    <div class="col-lg-2 col-md-3 col-sm-4 col-xs-12">
                                        <div class="product-grid transition">
                                            <div class="actions">
                                                <div class="image">
                                                    <a href="{{url_for('home.goods_detail',id = item.id)}}"><img
                                                        src="{{url_for('static',filename='images/goods/'+item.picture)}}"> </a>
                                                </div>
                                                <div class="button-group">
                                                    <div class="cart">
                                                        <input type="hidden" id="addCount_{{item.id}}" value="0" />
                                                        <button class="btn btn-primary btn-primary" type="button"
                                                            data-toggle="tooltip" title=""
                                                            onclick='javascript:
                                                                // alert(1)
                                                                    // 获取当前商品已添加的次数
                                                                    var addCount = parseInt(document.getElementById("addCount_{{item.id}}").value);
                                                                 // alert(addCount)
                                                                    // 每次点击累加次数
                                                                    addCount++;
                                                                    // 更新隐藏域中的次数值
                                                                    document.getElementById("addCount_{{item.id}}").value = addCount;
                                                                // alert(addCount)

                                                                    window.location.href="/cart_add/?goods_id={{item.id}}&number=" + addCount; '
                                                            data-original-title="加入购物车">
                                                            <i class="fa fa-shopping-cart"></i>
                                                        </button>
                                                    </div>

                                                </div>
                                            </div>
                                            <div class="caption">
                                                <div class="name" style="height: 40px">
                                                    <a style="width: 90%" href="{{url_for('home.goods_detail', id=item.id) }}">{{item.name}} </a>
                                                </div>
                                                <p class="price" style="margin-top: 40px">
                                                    <span class="price-tax">价格:{{item.current_price}}元
                                                    </span>
                                                </p>
                                            </div>
                                        </div>
                                    </div>
                                    {% endfor %}
                                    </div>
                                    <!-- // 显示底部相关商品 -->
									<!-- // 显示底部相关商品 -->
								</div>
								<!-- //显示相关商品 -->
								<!-- //根据商品ID获取并显示商品信息 -->
							</div>
						</div>
					</div>

				</div>
			</div>
			<!-- //页面主体内容 -->
			<!-- 显示左侧热门商品 -->
            <div class="mr-sidebar mr-sidebar-left col-xs-12 col-sm-4 col-sm-pull-8 col-md-3 col-md-pull-9  hidden-sm hidden-xs">
                <div class="mr-module module " id="Mod157">
                    <div class="module-inner">
                        <h3 class="module-title ">
                            <span>热门商品</span>
                        </h3>
                        <div class="module-ct">
                            <div class="mrshop">
                                <div class="container_oc">
                                    <div class="box_oc">
                                        <div>
                                            <div class="box-product product-grid">
                                                {% for item in hot_goods %}
                                                <div>
                                                    <div class="image">
                                                        <a href="{{url_for('home.goods_detail',id = item.id)}}"><img
                                                            src="{{url_for('static',filename='images/goods/'+item.picture)}}" width="80px">
                                                        </a>
                                                    </div>
                                                    <div class="name">
                                                        <a href="{{url_for('home.goods_detail',id = item.id)}}"> {{item.name}}
                                                        </a>
                                                    </div>
                                                    <div class="rating">
                                                        <span class="fa fa-stack"><i
                                                            class="fa fa-star fa-stack-2x"></i><i
                                                            class="fa fa-star-o fa-stack-2x"></i></span> <span
                                                            class="fa fa-stack"><i class="fa fa-star fa-stack-2x"></i><i
                                                            class="fa fa-star-o fa-stack-2x"></i></span> <span
                                                            class="fa fa-stack"><i class="fa fa-star fa-stack-2x"></i><i
                                                            class="fa fa-star-o fa-stack-2x"></i></span> <span
                                                            class="fa fa-stack"><i class="fa fa-star fa-stack-2x"></i><i
                                                            class="fa fa-star-o fa-stack-2x"></i></span> <span
                                                            class="fa fa-stack"><i class="fa fa-star fa-stack-2x"></i><i
                                                            class="fa fa-star-o fa-stack-2x"></i></span>
                                                    </div>
                                                    <div class="price">
                                                        {{item.current_price}}元
                                                    </div>
                                                </div>
                                                {% endfor %}
                                            </div>
                                        </div>
                                    </div>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
            <!-- // 显示左侧热门商品 -->
            </div>
            </div>
<script src="{{url_for('static',filename='home/js/jquery.1.3.2.js')}}" type="text/javascript"></script>
<script type="text/javascript">
function addCart_detail() {
    var user_id = {{ user_id }}; //获取当前用户的id
    var goods_id = {{ goods.id }}
    if( !user_id){
        window.location.href = "/login/"; //如果没有登录，跳转到登录页
        return ;
    }
    var number = $('#shuliang').val();//获取输入的商品数量
    //验证输入的数量是否合法
    if (number < 1) {//如果输入的数量不合法
        alert('数量不能小于1！');
        return;
    }
    window.location.href = '/cart_add?goods_id='+goods_id+"&number="+number
    }
</script>
{% endblock %}
